package com.lagou.edu.wwyan.web1.minicat;

import java.io.IOException;
import java.io.InputStream;

public class Request {
    private String url;
    private String host;
    private InputStream inputStream;
    private String method;

    public Request() {
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;

        int count = 0;
        //这里是处理网络请求的数据可能还没发送到服务器的问题
        while (count == 0){
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);
        String inputStr = new String(bytes);
        //请求头
        String[] heads = inputStr.split("\\r?\\n");
        String heardStr = heads[0];
        String[] split = heardStr.split(" ");
        method = split[0];
        url = split[1];
        String hostStr = heads[1];
        host = hostStr.split(":")[1].trim();

    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }
}
